//
//  CarsHeaderView.m
//  HonlivApp
//
//  Created by admin on 2017/6/26.
//  Copyright © 2017年 honliv. All rights reserved.
//

#import "CarsHeaderView.h"
#import "CarsGroupModel.h"
#import "CarsModel.h"
#import "NSString+Extension.h"

@interface CarsHeaderView ()

@property (nonatomic,weak) UILabel *titleLab;
@property (nonatomic,weak) UILabel *dateLab;
@property (nonatomic,weak) UILabel *destLab;
@property (nonatomic,weak) UIButton *arrowBtn;

@end

@implementation CarsHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
    
        UILabel *titleLab = [Factory createLabelWithTitle:@"" frame:CGRectMake(10, 0, kScreenW-20, 30) fontSize:15];
        [self addSubview:titleLab];
        self.titleLab = titleLab;
    
        UILabel *dateLab = [Factory createLabelWithTitle:@"" frame:CGRectMake(10, titleLab.bottom, 100, 30) fontSize:15];
        dateLab.textColor = [UIColor redColor];
        [self addSubview:dateLab];
        self.dateLab = dateLab;
        
        UILabel *destLab = [Factory createLabelWithTitle:@"" frame:CGRectMake(dateLab.right+10, titleLab.bottom, (kScreenW-dateLab.right-50), 30) fontSize:14];
        [self addSubview:destLab];
        self.destLab = destLab;
    
        UIButton *btn = [Factory createButtonWithTitle:nil frame:CGRectMake(kScreenW - 40, 0, 40, 60) target:nil selector:nil];
        btn.imageEdgeInsets = UIEdgeInsetsMake(20, 0, 0, 0);
        [btn setImage:[UIImage imageNamed:@"group_img"] forState:UIControlStateNormal];
        [self addSubview:btn];
        self.arrowBtn = btn;
        
        self.backgroundColor = [UIColor whiteColor];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureClicked:)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

-(void)viewClicked:(Clicked)block{
    self.clicked = block;
}
-(void)gestureClicked:(UITapGestureRecognizer *)tap{
    if (self.clicked) {
        self.clicked();
    }
}

-(void)setGroup:(CarsGroupModel *)group{
    _group = group;
     CarsModel *cars = group.carsModel;
    NSString *title = [NSString stringWithFormat:@"%@  (%@)",cars.partment,cars.carName];
    NSRange range = [title rangeOfString:cars.carName];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:title];
    [attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} range:range];
    [self.titleLab setAttributedText:attribute];
    
     NSString *date = [cars.date stringWithYMD];
    self.dateLab.text = date;
    
     NSString *dest = [NSString stringWithFormat:@"目的地：%@",cars.destination];
    self.destLab.text = dest;
    
    if (group.isShow) {
        self.arrowBtn.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
    }
}

@end
